package com.ruoyi.wechat.api;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.wechat.domain.Project;
import com.ruoyi.wechat.service.IProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wechat/project")
public class WxProjectController extends BaseController {
    @Autowired
    private IProjectService projectService;

    /**
     * 新增项目
     *
     * @param project
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Project project) {
        if (project == null) {
            return error("数据不能为空");
        }
        if (project.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (project.getProjectName() == null) {
            return error("其他项目名称不能为空");
        }
        if (project.getOriginalPrice() == null) {
            return error("原价不能为空");
        }
        return toAjax(projectService.insertProject(project));
    }

    /**
     * 根据营地id查询项目列表
     *
     * @param project
     * @return
     */
    @GetMapping("/getInfoByCampId")
    public AjaxResult getInfoByCampId(Project project){
        if(project.getCampId() == null){
            return error("营地Id不能为空");
        }
        List<Project> list = projectService.selectProjectList(project);
        return  success(list);
    }

    /**
     * 根据项目id查询项目详情
     *
     * @param projectId
     * @return
     */
    @GetMapping("/getInfoByProjectId/{projectId}")
    public AjaxResult getInfoByScenicId(@PathVariable("projectId") String projectId){
        if(projectId == null){
            return error("其他项目Id不能为空");
        }
        Project project = projectService.selectProjectByProjectId(projectId);
        return success(project);
    }

    /**
     * 删除项目
     *
     * @param projectId
     * @return
     */
    @DeleteMapping("/delete/{projectId}")
    public AjaxResult delete(@PathVariable("projectId") String projectId){
        if(projectId == null){
            return error("其他项目Id不能为空");
        }
        return  toAjax(projectService.deleteProjectByProjectId(projectId));
    }
}
